package cn.szzsi.model;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.model.base.BaseRole;
import com.jfinal.core.JFinal;
import com.jfinal.kit.StrKit;

import java.io.File;
import java.util.List;

/**
 * 实体类 - 角色
 * 
 */
public class Role extends BaseRole<Role> {

	private static final long serialVersionUID = 4675418211373785326L;
	
	public static final Role dao = new Role().dao();

	public List<Role> getAll(){
		return dao.find("select * from sys_role where uid='"+ CommonUtil.PLATFROM_FLAG+"'");
	}

	public List<Role> getBusinessAll(String uid){
		return dao.find("select * from sys_role where uid=?",uid);
	}

	public List<Role> getByUid(String uid){
		return dao.find("select * from sys_role where uid=?",uid);
	}

	// 重写delete
	public boolean delete(String id){
		Role brand = dao.findById(id);
		//删除logo文件
		if (StrKit.notBlank(brand.getStr("logo"))){
			File logoFile = new File(JFinal.me().getServletContext().getRealPath(brand.getStr("logo")));
			if (logoFile.exists()) {
				logoFile.delete();
			}
		}		
		return brand.delete();
	}
}
